#pragma once

#include "../umlmodel_global.h"

#include <memory>
#include <vector>

#include "ActivityNode.h"
#include "ObjectNodeOrderingKind.h"
#include "TypedElement.h"

using std::make_shared;
using std::shared_ptr;
using std::vector;

namespace uml {
class Behavior;
class State;
class ValueSpecification;

/// <summary>
/// ObjectNode
/// An ObjectNode is an abstract ActivityNode that may hold tokens within the object
/// flow in an Activity. ObjectNodes also support token selection, limitation on the
/// number of tokens held, specification of the state required for tokens being
/// held, and carrying control values.
/// 
/// </summary>
class UMLMODEL_EXPORT ObjectNode : public ActivityNode, public TypedElement {

public: // Constructors and destructors
    explicit ObjectNode(const QString& umlType="uml::ObjectNode");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Properties
    /// <summary>
    /// inStates getter
    /// The States required to be associated with the values held by tokens on this
    /// ObjectNode.
    /// </summary>
    vector<shared_ptr<State>>& inStates();

    /// <summary>
    /// isControlType getter
    /// Indicates whether the type of the ObjectNode is to be treated as representing
    /// control values that may traverse ControlFlows.
    /// </summary>
    bool isControlType() const;

    /// <summary>
    /// isControlType setter
    /// Indicates whether the type of the ObjectNode is to be treated as representing
    /// control values that may traverse ControlFlows.
    /// </summary>
    void setIsControlType(bool value);

    /// <summary>
    /// ordering getter
    /// Indicates how the tokens held by the ObjectNode are ordered for selection to
    /// traverse ActivityEdges outgoing from the ObjectNode.
    /// </summary>
    ObjectNodeOrderingKind ordering() const;

    /// <summary>
    /// ordering setter
    /// Indicates how the tokens held by the ObjectNode are ordered for selection to
    /// traverse ActivityEdges outgoing from the ObjectNode.
    /// </summary>
    void setOrdering(ObjectNodeOrderingKind value);

    /// <summary>
    /// selection getter
    /// A Behavior used to select tokens to be offered on outgoing ActivityEdges.
    /// </summary>
    shared_ptr<Behavior> selection() const;

    /// <summary>
    /// selection setter
    /// A Behavior used to select tokens to be offered on outgoing ActivityEdges.
    /// </summary>
    void setSelection(shared_ptr<Behavior> value);

    /// <summary>
    /// upperBound getter
    /// The maximum number of tokens that may be held by this ObjectNode. Tokens cannot
    /// flow into the ObjectNode if the upperBound is reached. If no upperBound is
    /// specified, then there is no limit on how many tokens the ObjectNode can hold.
    /// </summary>
    shared_ptr<ValueSpecification> upperBound() const;

    /// <summary>
    /// upperBound setter
    /// The maximum number of tokens that may be held by this ObjectNode. Tokens cannot
    /// flow into the ObjectNode if the upperBound is reached. If no upperBound is
    /// specified, then there is no limit on how many tokens the ObjectNode can hold.
    /// </summary>
    void setUpperBound(shared_ptr<ValueSpecification> value);

private: // Fields
    /// <summary>
    /// inStates
    /// The States required to be associated with the values held by tokens on this
    /// ObjectNode.
    /// </summary>
    vector<shared_ptr<State>> inStates_;

    /// <summary>
    /// isControlType
    /// Indicates whether the type of the ObjectNode is to be treated as representing
    /// control values that may traverse ControlFlows.
    /// </summary>
    const static bool isControlType_default_;
    bool isControlType_= isControlType_default_;

    /// <summary>
    /// ordering
    /// Indicates how the tokens held by the ObjectNode are ordered for selection to
    /// traverse ActivityEdges outgoing from the ObjectNode.
    /// </summary>
    ObjectNodeOrderingKind ordering_ = ObjectNodeOrderingKind::kFIFO;

    /// <summary>
    /// selection
    /// A Behavior used to select tokens to be offered on outgoing ActivityEdges.
    /// </summary>
    shared_ptr<Behavior> selection_;

    /// <summary>
    /// upperBound
    /// The maximum number of tokens that may be held by this ObjectNode. Tokens cannot
    /// flow into the ObjectNode if the upperBound is reached. If no upperBound is
    /// specified, then there is no limit on how many tokens the ObjectNode can hold.
    /// </summary>
    shared_ptr<ValueSpecification> upperBound_;

};

} // namespace uml
